package cn.kys.task;

import cn.kys.modules.monitor.service.VisitsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**功能描述：定时统计流量
 * @Auther:http://www.kys.cn
 * @Date:2020/4/1
 * @Description:cn.kys.task
 * @version:1.0
 */
@EnableScheduling
@Slf4j
@Component
public class VisitsScheduledTask {

    private final VisitsService visitsService;

    public VisitsScheduledTask(VisitsService visitsService) {
        this.visitsService = visitsService;
    }

    /**
     * 每日0点创建新的访客记录
     */
    @Scheduled(cron="0 0 0 * * ?")
    public void countVisits() {
        log.info("每分钟执行一次");
        System.out.println("--------------- 定时器启动流量统计，如果存在今日统计则跳过 ---------------");
        visitsService.save();
        System.out.println("--------------- 定时器启动流量统计完成 ---------------");
    }

}
